package exampleSupport {
	import com.transmote.flar.marker.FLARMarker;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.libspark.flartoolkit.core.types.FLARDoublePoint2d;
	
	/**
	 * simple class to draw outlines around detected markers.
	 * 
	 * @author	Eric Socolofsky
	 * @url		http://transmote.com/flar
	 */
	public class MarkerOutliner extends Sprite {
		public function MarkerOutliner () {
			this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
		}
		
		public function drawOutline (marker:FLARMarker, downsampleRatio:Number, thickness:Number, color:Number) :void {
			this.graphics.lineStyle(thickness, color);
			var vertex:FLARDoublePoint2d = FLARDoublePoint2d(marker.outline.sqvertex[0]);
			this.graphics.moveTo(vertex.x/downsampleRatio, vertex.y/downsampleRatio);
			for (var i:uint=1; i<marker.outline.sqvertex.length; i++) {
				vertex = FLARDoublePoint2d(marker.outline.sqvertex[i]);
				this.graphics.lineTo(vertex.x/downsampleRatio, vertex.y/downsampleRatio)
			}
			vertex = FLARDoublePoint2d(marker.outline.sqvertex[0]);
			this.graphics.lineTo(vertex.x/downsampleRatio, vertex.y/downsampleRatio);
		}
		
		public function getMarkerCoords(marker:FLARMarker, downsampleRatio:Number) :FLARDoublePoint2d {
			var vertex:FLARDoublePoint2d = FLARDoublePoint2d(marker.outline.sqvertex[2]);
			vertex.x = vertex.x / downsampleRatio;
			vertex.y = vertex.y / downsampleRatio;
			return vertex;
		}
		
		public function drawRectangle(vertex:FLARDoublePoint2d,width:Number,height:Number) :void {
			this.graphics.lineStyle(3.5, 0xF2F2B2);
			this.graphics.drawRect(vertex.x,vertex.y,width,height);
		}
		
		public function drawBall(x:Number,y:Number,radius:Number) :void {
			this.graphics.lineStyle(3, 0xFF0000);
			this.graphics.drawCircle(x,y,radius);
		}
		
		private function onEnterFrame (evt:Event) :void {
			this.graphics.clear();
		}
	}
}